﻿using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;

using xEngine.Rendering;
using xEngine.Utils;
using xEngine.Debugging;

namespace xEngine.UI.Screens
{
    public class ScreenSplash : Screen
    {
        #region Member Variables

        private Texture2D _splash;
        private String _img;
        private float _scale;
        private float _speed;
        private float _time;

        #endregion

        #region Properties
        #endregion

        #region Constructors

        public ScreenSplash(String image, float startScale, float speed, float time, Keys? skipBtn) : base(skipBtn)
        {
            _img = image;
            _scale = startScale;
            _speed = speed;
            _time = time;

            ProcessMouse = false;
        }

        #endregion

        #region Functions

        public override void LoadContent()
        {
            _splash = ScreenManager.Game.Content.Load<Texture2D>(_img);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            _scale += (float)(_speed * gameTime.ElapsedGameTime.TotalSeconds);
            _time -= (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (_time <= FadeTimeout)
                FadeOut();
        }

        public override void Render(GameTime gameTime)
        {
            Vector2 scale = ScreenManager.DesignScale.ToVector2() * _scale;

            Vector2 pos = new Vector2(
                (ScreenManager.GraphicsDevice.Viewport.Width - _splash.Width * scale.X) / 2,
                (ScreenManager.GraphicsDevice.Viewport.Height - _splash.Height * scale.Y) / 2
            );

            ScreenManager.SpriteBatch.Begin();
            ScreenManager.SpriteBatch.Draw(_splash, pos, null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 1);
            ScreenManager.SpriteBatch.End();

            base.Render(gameTime);
        }

        #endregion
    }
}
